package cn.edu.gdpt.mobile213.mobile2121606097wjc0501;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class StudentRVAdapter extends RecyclerView.Adapter<StudentRVAdapter.ViewHolder>{
    private List<Student>list;
    public StudentRVAdapter(List<Student>list){
        this.list=list;
    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvNum,tvName,tvGender,tvAdd;
        public ViewHolder(@NonNull View itemView){
            super(itemView);
            tvNum=itemView.findViewById(R.id.tvitemNum);
            tvName=itemView.findViewById(R.id.tvitemName);
            tvGender=itemView.findViewById(R.id.tvitemGender);
            tvAdd=itemView.findViewById(R.id.tvitemAdd);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_student,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Student student=list.get(position);
        holder.tvNum.setText(student.getNum());
        holder.tvName.setText(student.getName());
        holder.tvGender.setText(student.getGender());
        holder.tvAdd.setText(student.getAdd());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

}
